#include<stdio.h>
#define N 6
typedef struct hjx
{
    int *a;
    int top;
    int wei;
}hjx;
void chushihua(hjx*p)
{
    p->top=0;
    p->wei=0;
    p->a=(int*)malloc(sizeof(int)*N);
}
int pangkong(hjx**p)
{
    return (*p)->top==(*p)->wei;
}
int panman(hjx*p)
{
    return (p->wei+1)%N==p->top;
}
void charu(hjx*p,int x)
{
    if(panman(p))
    {
        return;
    }
    else
    {
       p->a[p->wei]=x;
       p->wei=(p->wei+1)%N;
    }
}
int chang(hjx*p)
{
    int c=(p->wei-p->top+N)%N;
    return c;
}
void print(hjx p)
{
    int i;
    int c=chang(&p);
    int j=p.top;
    for(i=0;i<c;i++)
    {
        printf("%d ",p.a[j]);
        j=(j+1)%N;

    }
    printf("\n");
}
void shanchu(hjx*p)
{
    if(pangkong(p))
    {
        return;
    }
    else
    {
        p->top=(p->top+1)%N;
    }
}
int qutop(hjx*p)
{
    if(!pangkong(p))
    {
        return p->a[p->top];

    }
}
int quwei(hjx*p)
{
    if(!pangkong(p))
    {
        int tail=p->wei-1;
        if(tail==-1)
        {
            tail=N-1;
        }
        return p->a[tail];
    }
}
int main()
{
    hjx p;
    chushihua(&p);
    charu(&p,1);
    charu(&p,2);
    print(p);
    shanchu(&p);
    print(p);
    charu(&p,3);
    charu(&p,4);
    charu(&p,5);
    charu(&p,6);
    shanchu(&p);
    charu(&p,7);
    print(p);
    int ret=qutop(&p);
    printf("%d ",ret);
    ret=quwei(&p);
    printf("%d ",ret);
    return 0;
}
